//
//  TOFooterView.m
//  B段项目
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "TOFooterView.h"

@implementation TOFooterView


-(instancetype)init
{
    self = [super init];
    if (self) {
        [self createSubview];
    }
    
    return self;
}

-(void)createSubview
{
    //专辑图片
    self.specialImageView = [[UIImageView alloc] init];
    self.specialImageView.image = [UIImage imageNamed:@"MusicImage.png"];
    [self addSubview:self.specialImageView];
    
    [self.specialImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.mas_equalTo(self).offset(WIDTH/37.5);
        make.width.height.equalTo(self.mas_height).multipliedBy(0.8);
    }];
    
    
   
    
    
    //标题
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:self.titleLabel];
    self.titleLabel.textColor = [UIColor whiteColor];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.specialImageView).offset(5);
        make.left.mas_equalTo(self.specialImageView.mas_right).offset(5);
        make.width.mas_equalTo(self).multipliedBy(0.4);
        make.height.mas_equalTo(self).multipliedBy(0.3);
    }];
    
    
    //副标题
    self.subTitle = [[UILabel alloc] init];
    self.subTitle.backgroundColor = [UIColor clearColor];
    self.subTitle.font = [UIFont systemFontOfSize:15];
    self.subTitle.textColor = [UIColor whiteColor];
    [self addSubview:self.subTitle];
    
    [self.subTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(self.titleLabel);
        make.width.height.mas_equalTo(self.titleLabel);
    }];

    
    //播放/停止按钮
    self.playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:self.playBtn];
    [self.playBtn setImage:[UIImage imageNamed:@"DWbofang1.png"] forState:UIControlStateNormal];
    [self.playBtn addTarget:self action:@selector(playBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.specialImageView);
        make.left.mas_equalTo(self.titleLabel.mas_right).offset(10);
        make.width.height.mas_equalTo(self.specialImageView).multipliedBy(0.5);
        
        
    }];
}
-(void)playBtnAction:(UIButton *)btn
{
    if ([ZZCMusicPlayerViewController shareMusicPlayerViewController].player.state == STKAudioPlayerStatePaused) {
        btn.selected = NO;
    }
    else if([ZZCMusicPlayerViewController shareMusicPlayerViewController].player.state == STKAudioPlayerStatePlaying)
    {
        btn.selected = YES;
    }
    
    if (!btn.selected) {
        [btn setImage:[UIImage imageNamed:@"iconfont-zanting-3.png"] forState:UIControlStateNormal];
        [[ZZCMusicPlayerViewController shareMusicPlayerViewController].player resume];
    }
    else
    {
        [self.playBtn setImage:[UIImage imageNamed:@"DWbofang1.png"] forState:UIControlStateNormal];
        [[ZZCMusicPlayerViewController shareMusicPlayerViewController].player pause];

    }
    
    btn.selected = !btn.selected;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
